/**
 * @Author：ming
 * @Date：2023/10/3 4:47 PM
 * @Filename：Lc432
 */


/**
 * @author ming
 */
public class Lc437 {

    public int pathSum(TreeNode root, int targetSum) {
        if (root == null) {
            return 0;
        }

        return getNum(root, targetSum) + pathSum(root.left, targetSum) + pathSum(root.right, targetSum);


    }

    public static int getNum(TreeNode root, long sum) {
        if (root == null) {
            return 0;
        }
        int count = 0;
        if (sum == root.val) {
            count++;
        }
        sum -= root.val;

        return count + getNum(root.left, sum) + getNum(root.right, sum);
    }


}
